package com.ruoyi.mall.service.impl;

import java.util.List;

import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.PrimaryKeyIdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.ProductTagMapper;
import com.ruoyi.mall.domain.ProductTag;
import com.ruoyi.mall.service.IProductTagService;

/**
 * 商品标签Service业务层处理
 * 
 * @author luogongquan
 * @date 2024-10-09
 */
@Service
public class ProductTagServiceImpl implements IProductTagService 
{
    @Autowired
    private ProductTagMapper productTagMapper;

    /**
     * 查询商品标签
     * 
     * @param id 商品标签主键
     * @return 商品标签
     */
    @Override
    public ProductTag selectProductTagById(Long id)
    {
        return productTagMapper.selectProductTagById(id);
    }

    /**
     * 查询商品标签列表
     * 
     * @param productTag 商品标签
     * @return 商品标签
     */
    @Override
    public List<ProductTag> selectProductTagList(ProductTag productTag)
    {
        return productTagMapper.selectProductTagList(productTag);
    }

    /**
     * 新增商品标签
     * 
     * @param productTag 商品标签
     * @return 结果
     */
    @Override
    public int insertProductTag(ProductTag productTag)
    {
        //判断是否已经存在相同编码
        ProductTag old = productTagMapper.selectProductTagByCode(productTag.getCode());
        if(old!=null){
            throw new ServiceException("已经存在该标签编码了！");
        }
        productTag.setId(PrimaryKeyIdUtils.getSysIdWorker().nextId());
        productTag.setCreateTime(DateUtils.getNowDate());
        return productTagMapper.insertProductTag(productTag);
    }

    /**
     * 修改商品标签
     * 
     * @param productTag 商品标签
     * @return 结果
     */
    @Override
    public int updateProductTag(ProductTag productTag)
    {
        productTag.setUpdateTime(DateUtils.getNowDate());
        return productTagMapper.updateProductTag(productTag);
    }

    /**
     * 批量删除商品标签
     * 
     * @param ids 需要删除的商品标签主键
     * @return 结果
     */
    @Override
    public int deleteProductTagByIds(Long[] ids)
    {
        return productTagMapper.deleteProductTagByIds(ids);
    }

    /**
     * 删除商品标签信息
     * 
     * @param id 商品标签主键
     * @return 结果
     */
    @Override
    public int deleteProductTagById(Long id)
    {
        return productTagMapper.deleteProductTagById(id);
    }
}
